package intelligentCustomer.planning;

import dev.langchain4j.model.openai.OpenAiStreamingChatModel;

/**
 * 比较步骤
 * 比较不同选项
 */
public class ComparisonStep implements PlanStep {
    private final String name;
    private final OpenAiStreamingChatModel model;
    private int comparisonDepth = 1; // 比较深度，用于调整
    
    public ComparisonStep(String name, OpenAiStreamingChatModel model) {
        this.name = name;
        this.model = model;
    }
    
    @Override
    public String execute(PlanningContext context) {
        // 获取前一步的搜索结果
        String searchResults = context.getResult("产品搜索");
        
        String prompt = String.format(
            "基于以下搜索结果，比较不同选项。比较深度：%d\n" +
            "搜索结果：%s\n" +
            "原始查询：%s\n" +
            "请提供详细的比较分析。",
            comparisonDepth,
            searchResults != null ? searchResults : "未提供",
            context.getQuery()
        );
        
        return ReasonGenerator.generate(model, prompt);
    }
    
    @Override
    public String getName() {
        return name;
    }
    
    @Override
    public void adjustParameters(PlanningContext context) {
        // 根据重试次数增加比较深度
        comparisonDepth = Math.min(3, comparisonDepth + 1);
    }
} 